import requests
import hashlib
import json
import datetime

# 登录
# 构造请求头
loginName = 'jsh'
password = '123456'
md5 = hashlib.md5(password.encode())  # 创建MD5对象
password_md5 = md5.hexdigest()  # 调用方法hexdigest()加密
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0'
    , 'Content-Type': 'application/json;charset=UTF-8'
}
# 构造请求url
url = r'http://192.168.4.7:3000/jshERP-boot/user/login'

# 构造data
json1 = {"loginName": loginName, "password": password_md5}
# 发送请求
resp = requests.post(url, headers=headers, json=json1, verify=False)
# 获取响应
resp = resp.json()
token = resp['data']['token']
print(token)

# 零售管理-零售出库-新增
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造请求url
# url=r'http://192.168.4.7:3000/jshERP-boot/depotHead/addDepotHeadAndDetail'
# # 构造data
# organId=77
# number='LSCK00000000673'
# accountId=22
# defaultNumber='LSCK00000000673'
# info_dict1={"organId":organId,"operTime":"2024-01-12 12:03:32","number":number,"payType":"现付","changeAmount":"1000.00","getAmount":"1000.00","backAmount":0,"accountId":accountId,"type":"出库","subType":"零售","defaultNumber":defaultNumber,"totalPrice":1000,"fileName":"","status":"0"}
# info_str1 = json.dumps(info_dict1)  # 把内层字典转成串
# name='洗面奶'
# operNumber=20
# allPrice=2000
# info_dict2=[{"id":"17050322123760145435","name":name,"standard":"100g","model":"","color":"","materialOther":"","stock":0,"unit":"只","snList":"","batchNumber":"","expirationDate":"","sku":"","operNumber":operNumber,"unitPrice":100,"allPrice":allPrice,"remark":"","orderNum":1,"depotId":"19","barCode":"1019"}]
# info_str2 = json.dumps(info_dict2)  # 把内层字典转成串
# data={
#     'info':info_str1,
#     'rows':info_str2
# }
#
# # 发送请求
# resp = requests.post(url, headers=headers, json=data, verify=False)
# # 获取响应
# print(resp.text)


# 零售管理-零售出库-编辑
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造请求url
# url=r'http://192.168.4.7:3000/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# # 构造data
# info1={"id":5259,"type":"出库","subType":"零售","defaultNumber":"LSCK00000000671","number":"LSCK00000000671","createTime":"2024-01-12T04:04:00.000+0000","operTime":"2024-01-12 12:03:32","organId":77,"creator":63,"accountId":20,"changeAmount":"10000.00","backAmount":0,"totalPrice":10000,"payType":"现付","billType":"","remark":"","fileName":"","salesMan":"","accountIdList":"","accountMoneyList":"","discount":"","discountMoney":"","discountLastMoney":0,"otherMoney":"","deposit":0,"status":"0","purchaseStatus":"0","source":"0","linkNumber":"","tenantId":63,"deleteFlag":"0","projectName":"","organName":"001","userName":"","accountName":"洗面奶账户","allocationProjectName":"","materialsList":"洗面奶 100g ","salesManStr":"","operTimeStr":"2024-01-12 12:03:32","finishDebt":"","depotHeadType":"零售出库","creatorName":"测试用户","contacts":"","telephone":"","address":"","finishDeposit":"","needDebt":"","debt":-1000,"materialCount":"","hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":"","getAmount":"10000.00"}
# info_str1 = json.dumps(info1)  # 把内层字典转成串
# operNumber=200
# allPrice=20000
# rows1=[{"id":"5318","name":"洗面奶","standard":"100g","model":"","color":"","materialOther":"","stock":"-10","unit":"只","snList":"","batchNumber":"","expirationDate":"","sku":"","operNumber":operNumber,"unitPrice":"100","allPrice":allPrice,"remark":"","orderNum":1,"depotId":"19","barCode":"1019"}]
# rows_str2 = json.dumps(rows1)  # 把内层字典转成串
# data={
#     'info':info_str1,
#     'rows':rows_str2
# }
# # 发送请求
# resp = requests.put(url, headers=headers, json=data, verify=False)
# # 获取响应
# print(resp.text)

# 零售管理-零售出库-查询
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造请求url
# url=r'http://192.168.4.7:3000/jshERP-boot/depotHead/list'
# # 构造data
#
# number="LSCK00000000671"
# materialParam=""
# organId=""
# depotId=""
# creator=""
# accountId=""
# status=""
# remark=""
# search_dict={"number":number,"materialParam":materialParam,"type":"出库","subType":"零售","roleType":"全部数据","organId":organId,"depotId":depotId,"creator":creator,"accountId":accountId,"status":status,"remark":remark}
# info_str1 = json.dumps(search_dict)  # 把内层字典转成串
# currentPage=1
# pageSize=10
# data={
#     'search':info_str1,
#     'column':'createTime',
#     'order':'desc',
#     'field':['id',"",'action','organName','number','materialsList','operTimeStr','userName','materialCount','totalPrice','getAmount','backAmount','status'],
#     'currentPage':currentPage,
#     'pageSize':pageSize
# }
# # 发送请求
# resp = requests.get(url, headers=headers, params=data, verify=False)
# # 获取响应
# print(resp.text)

# 零售管理-零售出库-删除
# # 构造请求头
headers['X-Access-Token'] = token
# 构造请求url
url=r'http://192.168.4.7:3000/jshERP-boot/depotHead/delete?id=5261'
# 构造data
id=5261
data={
    'id':id
}
# 发送请求
resp = requests.delete(url, headers=headers, params=data, verify=False)
# 获取响应
print(resp.text)
